import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/page/supplier/supplier_list_page.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/widgets/search_app_bar2.dart';

class SupplierSearchPage extends StatefulWidget {
  @override
  _SupplierSearchPageState createState() => _SupplierSearchPageState();
}

class _SupplierSearchPageState extends State<SupplierSearchPage> {
  String _keyword = "";

  GlobalKey<SupplierListPageState> _listKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: _initAppBar(), body: _initBody());
  }

  /// 导航
  Widget _initAppBar() {
    return SearchAppBarStyle2(
        onSearch: (value) {
          _keyword = value;
          _listKey.currentState.keyword = _keyword;
          _listKey.currentState.manualRefersh();
        },
        autoFocus: true,
        leading: FlatButton(
            onPressed: () {
              LRouter.navigatorCtx(context).pop();
            },
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
            child: Image.asset(
              RPath.imgPath + "icon_nav_back_balck.png",
              fit: BoxFit.contain,
              width: ScreenAdapter.width(30),
              height: ScreenAdapter.height(30),
            )));
  }

  /// 内容体
  Widget _initBody() {
    if (_keyword != null && _keyword.isNotEmpty) {
      return SupplierListPage(
        key: _listKey,
        keyword: _keyword,
        supplietType: AppConstant.SUPPLIER_ALL,
      );
    } else {
      return Container();
    }
  }
}
